<template>
  <div class="cmt-container">
    <h3>发表评论</h3>
    <hr>
    <textarea placeholder="请输入评论的内容" maxlength="120"></textarea>
    <mt-button type="primary" size="large">发表评论</mt-button>
    <div class="cmt-list">
      <div class="cmt-item" v-for="(item, index) in newList" :key="index">
        <div class="cmt-title">第+{{ index + 1 }}+lou &nbsp;</div>
        <div class="cmt-body">内容 &nbsp;</div>
      </div>
    </div>
    <mt-button type="danger" size="large" plain>加载更多</mt-button>
  </div>
</template>

<script>
import { Toast } from "mint-ui";
export default {
  data() {
    return {
      //  用于设置分页的数据
      pageIndex: 1,
      newList: []
    };
  },
  created() {
    this.getComments();
  },
  methods: {
    getComments() {
      this.$http
        .get("api/getComments/" + this.id + "?pageindex=" + this.pageIndex)
        .then(function(result) {
          if (result.body.status === 0) {
            //   在使用的时候，如果需要将新加载的数据添加到就数组中
            this.newList = this.newList.concat(result.body.message);
          } else {
            Toast("数据获取失败");
          }
        });
    },
    props: ["id"]
  }
};
</script>

<style lang="scss" scopes>
.cmt-container {
  h3 {
    font-size: 14px;
  }
  textarea {
    font-size: 14px;
    height: 85px;
    margin: 0;
  }
  .cmt-list {
    .cmt-item {
      .cmt-title {
        line-height: 35px;
        background-color: #ccc;
      }
      .cmt-body {
        line-height: 35px;
        text-indent: 2em;
      }
    }
  }
}
</style>
